//
//  AboutUsViewController.m
//  HongFuShop
//
//  Created by chirui on 2017/7/25.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "AboutUsViewController.h"
#import "AboutUsDetailsViewController.h"
#import "GoodsDetailsViewController.h"
#import "JuNengLolViewController.h"

@interface AboutUsViewController ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate>
{

    UITableView * _tableView;
    NSDictionary * dataDic;
    NSArray * bannerDataArray;
}

@end

@implementation AboutUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    TitleView(@"关于我们")
    
    [self creatTableView];
    
    [self getNetWorking];
    [self getBannerNetWorking];
}

-(void)creatTableView {
    
    _tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT- 64-48) style:UITableViewStyleGrouped];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.backgroundColor =[UIColor whiteColor];
    UIView * view =[[UIView alloc]init];
    _tableView.tableFooterView = view;
    [self.view addSubview:_tableView];
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 0;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    
    return 160 +(WIDTH/4)*1.25*3 +20;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 0.01;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    static NSString * cellid = @"cell";
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (cell==nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellid];
    }
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 120;
    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView * heardView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 160 +(WIDTH/4)*1.25*3 +20)];
    heardView.backgroundColor =[UIColor whiteColor];
    
    NSMutableArray * imageArrray = @[].mutableCopy;
    if (bannerDataArray.count>0) {
        
        if (imageArrray.count>0) {
            
            [imageArrray removeAllObjects];
        }
        
        for (NSDictionary * dic in bannerDataArray) {
            
            [imageArrray addObject:dic[@"src"]];
        }
    }
    
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, WIDTH, 160) delegate:self placeholderImage:[UIImage imageNamed:@"test_banner_icon"]];
    cycleScrollView.backgroundColor =Color(229, 229, 229);
    cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    cycleScrollView.currentPageDotColor = NavBackColor;
    //    cycleScrollView.imageURLStringsGroup = imageArrray;
    cycleScrollView.localizationImageNamesGroup = imageArrray;
    [heardView addSubview:cycleScrollView];
    cycleScrollView.clickItemOperationBlock = ^(NSInteger index) {
        
        NSDictionary * dic = bannerDataArray[index];
        
        if ([dic[@"go_type"] isEqualToString:@"goods"]) { //商品
            
            if (verifTokenAndEnter) {
                
                GoodsDetailsViewController * goods =[[GoodsDetailsViewController alloc]init];
                goods.hidesBottomBarWhenPushed = YES;
                goods.goodsId = dic[@"go_id"];
                [self.navigationController pushViewController:goods animated:YES];
            }else {
                
                LogingViewController * login =[[LogingViewController alloc]init];
                login.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:login animated:YES];
            }
        }
        if ([dic[@"go_type"] isEqualToString:@"news"]) { //新闻
            
            JuNengLolViewController * lol =[[JuNengLolViewController alloc]init];
            lol.newsIdStr = dic[@"go_id"];
            lol.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:lol animated:YES];
        }
        
    };

    
    float width  = WIDTH/4;
    
    NSArray * oneArray = @[@"icon_about_red",@"icon_about_company",@"icon_about_synopsis",@"icon_about_initiate"];
    NSArray * oneTitleArray = @[@"关于红福",@"公司展示",@"企业简介",@"企业创始人"];
    
    NSArray * twoArray = @[@"icon_about_culture",@"icon_about_glory",@"icon_about_shop",@"icon_about_service"];
    NSArray * twoTitleArray = @[@"企业文化",@"企业荣耀",@"购物指南",@"售后服务"];
    
    NSArray * threeArray = @[@"icon_about_recruitment",@"icon_about_contact",@"icon_about_seek"];
    NSArray * threeTitleArray = @[@"人才招聘",@"联系我们",@"找到我们"];
    
    UIView * oneView;
    UIView * twoView;
    UIView * threeView;
    for (int i = 0; i<4; i++) {
        
        oneView =[[UIView alloc]initWithFrame:CGRectMake(0 + width * i,CGRectGetMaxY(cycleScrollView.frame)+10 , width, width*1.25)];
        oneView.backgroundColor =[UIColor whiteColor];
        
        [oneView tapAction:^{
             AboutUsDetailsViewController * details = [[AboutUsDetailsViewController alloc]init];
             details.hidesBottomBarWhenPushed = YES;
            switch (i) {
                case 0:
                    details.titleStr = @"关于红福";
                    details.urlStr = dataDic[@"关于红福"];
                    break;
                case 1:
                    details.titleStr = @"公司展示";
                    details.urlStr = dataDic[@"公司展示"];
                    break;
                case 2:
                    details.titleStr = @"企业简介";
                    details.urlStr = dataDic[@"企业简介"];
                    break;
                case 3:
                    details.titleStr = @"企业创始人";
                    details.urlStr = dataDic[@"企业创始人"];
                    break;
                    
                default:
                    break;
            }
            
            [self.navigationController pushViewController:details animated:YES];
        }];
        
        
        UIImageView * imageView =[[UIImageView alloc]initWithFrame:CGRectMake((width - 50)/2, 10, 50, 50)];
        imageView.image = ImageName(oneArray[i]);
         [oneView addSubview:imageView];
        
        UILabel * label =[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame)+10, width, 20)];
        label.font = [UIFont systemFontOfSize:13];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = oneTitleArray[i];
        [oneView addSubview:label];
        
        [heardView addSubview:oneView];
        
    }
    
    for (int j = 0; j<4; j++) {
        
        twoView =[[UIView alloc]initWithFrame:CGRectMake(0 + width * j,CGRectGetMaxY(oneView.frame) , width, width*1.25)];
        twoView.backgroundColor =[UIColor whiteColor];
        [twoView tapAction:^{
            AboutUsDetailsViewController * details = [[AboutUsDetailsViewController alloc]init];
            details.hidesBottomBarWhenPushed = YES;
            switch (j) {
                case 0:
                    details.titleStr = @"企业文化";
                    details.urlStr = dataDic[@"企业文化"];
                    break;
                case 1:
                    details.titleStr = @"企业荣耀";
                    details.urlStr = dataDic[@"企业荣耀"];
                    break;
                case 2:
                    details.titleStr = @"购物指南";
                    details.urlStr = dataDic[@"购物指南"];
                    break;
                case 3:
                    details.titleStr = @"售后服务";
                    details.urlStr = dataDic[@"售后服务"];
                    break;
                default:
                    break;
            }
            
            [self.navigationController pushViewController:details animated:YES];
        }];

        
        UIImageView * imageView =[[UIImageView alloc]initWithFrame:CGRectMake((width - 50)/2, 10, 50, 50)];
        imageView.image = ImageName(twoArray[j]);
        [twoView addSubview:imageView];
        
        UILabel * label =[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame)+10, width, 20)];
        label.font = [UIFont systemFontOfSize:13];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = twoTitleArray[j];
        [twoView addSubview:label];
        
        [heardView addSubview:twoView];
        
    }

    for (int h = 0; h<2; h++) {
        
        threeView =[[UIView alloc]initWithFrame:CGRectMake(0 + width * h,CGRectGetMaxY(twoView.frame) , width, width*1.25)];
        threeView.backgroundColor =[UIColor whiteColor];
        
        [threeView tapAction:^{
            AboutUsDetailsViewController * details = [[AboutUsDetailsViewController alloc]init];
            details.hidesBottomBarWhenPushed = YES;
            switch (h) {
                case 0:
                    details.titleStr = @"人才招聘";
                    details.urlStr = dataDic[@"人才招聘"];
                    break;
                case 1:
                    details.titleStr = @"联系我们";
                    details.urlStr = dataDic[@"联系我们"];
                    break;
                default:
                    break;
            }
            
            [self.navigationController pushViewController:details animated:YES];
        }];

        
        
        UIImageView * imageView =[[UIImageView alloc]initWithFrame:CGRectMake((width - 50)/2, 10, 50, 50)];
        imageView.image = ImageName(threeArray[h]);
        [threeView addSubview:imageView];
        
        UILabel * label =[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame)+10, width, 20)];
        label.font = [UIFont systemFontOfSize:13];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = threeTitleArray[h];
        [threeView addSubview:label];
        
        [heardView addSubview:threeView];
        
    }
    return heardView;
}

// 网络请求
-(void)getNetWorking {
    
    NSString * parametersStr = [NSString stringWithFormat:@"%@%@",NetWorkAddress_api,AboutUs_class_api];
    
    SHuiMBhubNoTimeLoding;
    [PostNetWorking postNetWorkingStr:parametersStr  andparameters:nil  Success:^(id responseObject) {
        SHuiMBHidleYes;
        if ([responseObject[@"code"] intValue]==200) {
            
           dataDic = responseObject[@"datas"];
            
        } else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
        SHuiMBHidleYes;
        SHuiMBhudTextNetError;
        
    }];
    
    
}

-(void)getBannerNetWorking {
    
    
    NSString * parametersStr = [NSString stringWithFormat:@"%@%@",NetWorkAddress_api,get_banner_api];
    NSDictionary * dic = @{@"type":@"about"};

    [PostNetWorking postNetWorkingStr:parametersStr  andparameters:dic  Success:^(id responseObject) {
        SHuiMBHidleYes;
        if (codeSucess) {
            
            if ([responseObject[@"datas"] isKindOfClass:[NSArray class]]) {
                
                bannerDataArray = responseObject[@"datas"];
            }
            
        } else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
        [_tableView reloadData];
        
    } failed:^(NSError *error) {
        SHuiMBHidleYes;
        SHuiMBhudTextNetError;
        
    }];
    
    
}


@end
